/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.discoteca.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import pe.edu.upc.dew.discoteca.model.Contacto;
import pe.edu.upc.dew.discoteca.model.Lista;
import pe.edu.upc.dew.discoteca.service.DiscotecaService;

/**
 *
 * @author elvis
 */
@Controller
public class ReportesController {

   private static final Logger logger = Logger.getLogger(ReportesController.class);
   @Autowired
   DiscotecaService  discotecaService;

   @RequestMapping( method = RequestMethod.GET)
    public String intro( ModelMap model,HttpServletRequest req ){
        logger.debug("metodo intro GET");
         model.addAttribute( new Lista() );
        model.addAttribute( "discos", discotecaService.listarDiscotecas() );
       return "reportes/intro";
    }

    @RequestMapping( method = RequestMethod.POST)
    public String resultado( ModelMap model,HttpServletRequest req ){
        logger.debug("metodo resultado POSt");
        String fecha = "";
        String discoteca = "";
        model.put("listas", discotecaService.listaReservas(discoteca,fecha));
        
       return "reportes/resultado";
    }

    @RequestMapping( method = RequestMethod.GET)
    public String contactos(@RequestParam("id") Integer id, ModelMap model,HttpServletRequest req ){

       try {
       logger.debug("metodo contactos GET lista = " + id);
       model.put("lcontactos", discotecaService.listarContactos(id.toString()) );
       model.put("lista", discotecaService.obtenerLista(id.toString()));
       } catch (Exception e) {
          e.printStackTrace();
          return "reportes/resultado";
       }

       return "reportes/resultado2";
    }
}
